package com.inspur.zhangpeixia.goods.dao;

import com.inspur.zhangpeixia.goods.entity.User;
import com.inspur.zhangpeixia.goods.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LoginDao {

    private Connection connection= DBUtils.getConnection();
    public User login(String userAccount,String userPassword){
        try{
            System.out.println(userAccount);
            System.out.println(userPassword);
            String sql="select * from t_users where user_account=? and user_password=?";
            PreparedStatement pst = connection.prepareStatement(sql);
            pst.setString(1,userAccount);
            pst.setString(2,userPassword);
            ResultSet resultSet = pst.executeQuery();
            User user = null;
            while(resultSet.next()){
                user = new User();
                user.setUserId(resultSet.getInt("user_id"));
                user.setUserAccount(resultSet.getString("user_account"));
                user.setUserName(resultSet.getString("user_name"));
                user.setUserPassword(resultSet.getString("user_password"));
                user.setUserTel(resultSet.getString("user_tel"));

            }
            return user;
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
